﻿using System.Collections.Generic;
using System.Linq;

namespace QQ2564874169.Core.ORM
{
    public class PageResult<T>
    {
        public PageSet PageSet { get; }
        public int DataCount { get; }
        public int PageCount { get; }
        public T[] Data { get; }

        public PageResult(int index, int pageCount, int dataCount, IEnumerable<T> data)
            : this(new PageSet(index, pageCount), dataCount, data)
        {
        }

        public PageResult(PageSet pageset, int dataCount, IEnumerable<T> data)
        {
            Data = data.ToArray();
            PageSet = pageset;
            DataCount = dataCount;

            if (DataCount < pageset.Count)
            {
                PageCount = 1;
            }
            else
            {
                PageCount = DataCount / pageset.Count;
                if (PageCount * pageset.Count < DataCount)
                    PageCount++;
            }
        }
    }
}
